package com.simple;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author simple
 * @version 1.0
 * @date 2018-12-10 11:07
 * @since 1.0
 */
public class LogUtil {
    private static final String INFO = "INFO";
    private static final String WARN = "WARN";
    private static final String DEBUG = "DEBUG";
    private static final String ERROR = "ERROR";
    private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss,SSS";

    public static void info(String format, Object... args) {
        System.out.printf(new StringBuffer().append(now()).append(" ").append(INFO).append(" ").append(" - ").append(format).append("\n").toString(), args);
    }

    public static void info(String args) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(INFO).append(" ").append(" - ").toString() + args);
    }

    public static void info(Object o) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(INFO).append(" ").append(" - ").toString() + o.toString());
    }

    public static void warn(String format, Object... args) {
        System.out.printf(new StringBuffer().append(now()).append(" ").append(WARN).append(" ").append(" - ").append(format).append("\n").toString(), args);
    }

    public static void warn(String args) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(WARN).append(" ").append(" - ").toString() + args);
    }

    public static void warn(Object o) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(WARN).append(" ").append(" - ").toString() + o.toString());
    }

    public static void debug(String format, Object... args) {
        System.out.printf(new StringBuffer().append(now()).append(" ").append(DEBUG).append(" - ").append(format).append("\n").toString(), args);
    }

    public static void debug(String args) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(DEBUG).append(" - ").toString() + args);
    }

    public static void debug(Object o) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(DEBUG).append(" - ").toString() + o.toString());
    }

    public static void error(String format, Object... args) {
        System.out.printf(new StringBuffer().append(now()).append(" ").append(ERROR).append(" - ").append(format).append("\n").toString(), args);
    }

    public static void error(String args) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(ERROR).append(" - ").toString() + args);
    }

    public static void error(Object o) {
        System.out.println(new StringBuffer().append(now()).append(" ").append(ERROR).append(" - ").toString() + o.toString());
    }

    private static synchronized String now() {
        return new SimpleDateFormat(DATE_FORMAT).format(new Date());
    }
}
